{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "fef6f676",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "112\n"
     ]
    }
   ],
   "source": [
    "import cv2 as cv\n",
    "import numpy as np\n",
    "\n",
    "filePath = '../data/jWithWhiteNoise'\n",
    "# filePath = '../data/jWithBlackNoise'\n",
    "fileExtend = '.png'\n",
    "img = cv.imread(filePath+fileExtend,0)\n",
    "\n",
    "w = round(img.shape[1]/2)\n",
    "print(w)\n",
    "imgLH = img[:,:w]\n",
    "\n",
    "cv.imshow('imgLH', imgLH)\n",
    "\n",
    "if cv.waitKey(0) == ord('s'):\n",
    "    cv.imwrite(filePath+'Left'+fileExtend, imgLH)\n",
    "\n",
    "cv.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "bd7c3de1",
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2 as cv\n",
    "import numpy as np\n",
    "\n",
    "filePath = '../data/jWithWhiteNoiseLeft.png'\n",
    "img = cv.imread(filePath,0)\n",
    "kernel = np.ones((5,5),np.uint8)\n",
    "\n",
    "erosion = cv.erode(img,kernel,iterations = 1)\n",
    "dilation = cv.dilate(erosion,kernel,iterations = 1)\n",
    "\n",
    "res = np.hstack((img, erosion, dilation))\n",
    "\n",
    "# cv.imshow('img', img)\n",
    "# # cv.imshow('kernel', kernel)\n",
    "# cv.imshow('erosion', erosion)\n",
    "# cv.imshow('dilation', dilation)\n",
    "cv.imshow('res', res)\n",
    "\n",
    "cv.waitKey(0)\n",
    "cv.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "fd83a328",
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2 as cv\n",
    "import numpy as np\n",
    "\n",
    "# filePath = '../data/jWithWhiteNoiseLeft.png'\n",
    "filePath = '../data/j.png'\n",
    "img = cv.imread(filePath,0)\n",
    "kernel = np.ones((9,9),np.uint8)\n",
    "\n",
    "opening = cv.morphologyEx(img, cv.MORPH_OPEN, kernel)\n",
    "\n",
    "cv.imshow('img', img)\n",
    "# cv.imshow('kernel', kernel)\n",
    "cv.imshow('opening', opening)\n",
    "\n",
    "cv.waitKey(0)\n",
    "cv.destroyAllWindows()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "f3122f57",
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2 as cv\n",
    "import numpy as np\n",
    "\n",
    "img = cv.imread('../data/jWithBlackNoiseLeft.png',0)\n",
    "kernel = np.ones((5,5),np.uint8)\n",
    "\n",
    "\n",
    "dilation = cv.dilate(img,kernel,iterations = 1)\n",
    "erosion = cv.erode(dilation,kernel,iterations = 1)\n",
    "res = np.hstack((img, dilation, erosion))\n",
    "\n",
    "# cv.imshow('img', img)\n",
    "# cv.imshow('kernel', kernel)\n",
    "cv.imshow('res', res)\n",
    "\n",
    "cv.waitKey(0)\n",
    "cv.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "949d76ed",
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2 as cv\n",
    "import numpy as np\n",
    "\n",
    "img = cv.imread('../data/jWithBlackNoiseLeft.png',0)\n",
    "kernel = np.ones((5,5),np.uint8)\n",
    "\n",
    "closing = cv.morphologyEx(img, cv.MORPH_CLOSE, kernel)\n",
    "\n",
    "cv.imshow('img', img)\n",
    "# cv.imshow('kernel', kernel)\n",
    "cv.imshow('closing', closing)\n",
    "\n",
    "cv.waitKey(0)\n",
    "cv.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "420afa5b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
